home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-10-25 | 37.0 KB | 1,537 lines | [TEXT/MPS ] |
- {$P}
- {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]}
- {UMacApp.TControls.p}
- {Copyright © 1987-1990 by Apple Computer Inc. All rights reserved.}
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE ActionProcForTScrollBar(aCMgrControl: ControlHandle;
- partCode: INTEGER);
-
- VAR
- aScrollBar: TScrollBar;
-
- BEGIN
- aScrollBar := TScrollBar(GetCRefCon(aCMgrControl));
- FailNil(aScrollBar); { What else you gonna' do? }
-
- aScrollBar.ActionProc(partCode);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MASelCommand}
-
- PROCEDURE TControlTracker.IControlTracker(theControl: TControl);
-
- BEGIN
- INoChangesCommand(cTrackingControl, NIL, theControl, theControl.GetScroller(TRUE));
- {$IFC qDebug}
- IF theControl = NIL THEN
- ProgramBreak('Control passed to IControlTracker can''t be NIL.');
- {$ENDC}
- fControl := theControl;
- fTrackNonMovement := TRUE;
- fViewConstrain := FALSE;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAFields}
-
- PROCEDURE TControlTracker.Fields(PROCEDURE DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TControlTracker', NIL, bClass);
- DoToField('fControl', @fControl, bObject);
- INHERITED Fields(DoToField);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAOpen}
-
- PROCEDURE TControl.IControl(itsSuperView: TView;
- itsLocation, itsSize: VPoint;
- itsHSizeDet, itsVSizeDet: SizeDeterminer);
- VAR
- itsDocument: TDocument;
-
-
- BEGIN
- {$IFC qDebug}
- WITH itsSize DO
- IF (h > kMaxCoord) | (v > kMaxCoord) THEN
- ProgramBreak(ConcatNumber('The size in pixels of a TControl cannot exceed ', kMaxCoord));
- {$ENDC}
-
-
- { !!! Really need to have itsDocument come in through the parameter list (post 2.0)
- Make best guess for now. }
- IF itsSuperView <> NIL THEN
- itsDocument := itsSuperView.fDocument
- ELSE
- itsDocument := NIL;
-
- fTextStyle := gSystemStyle; { Put in safe state }
- IView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
- fDefChoice := mOKHit;
- fHilite := FALSE;
- fDimmed := FALSE;
- fSizeable := TRUE;
- fAdornment := [];
- fPenSize := Point($00010001);
- fInset := gZeroRect;
- fTextStyle := gSystemStyle;
- fDismissesDialog := FALSE;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAOpen}
-
- PROCEDURE TControl.IRes(itsDocument: TDocument;
- itsSuperView: TView;
- VAR itsParams: Ptr);
-
- VAR
- aTextStyle: TextStyle;
-
- BEGIN
- fTextStyle := gSystemStyle; { Put in safe state }
-
- INHERITED IRes(itsDocument, itsSuperView, itsParams);
-
- WITH ControlTemplatePtr(itsParams)^ DO
- BEGIN
- fDefChoice := mOKHit; {??? This seems questionable}
- fAdornment := itsAdornment;
- fSizeable := isSizable;
- fHilite := isHilited;
- fDimmed := isDimmed;
- fDismissesDialog := canDismiss;
- fInset := itsInset;
- fPenSize := itsPenSize;
- SetTextStyle(aTextStyle, GetFontNum(itsFontName), itsTextFace, itsTextSize, itsTextColor);
- fTextStyle := aTextStyle;
-
- OffsetPtrWStr(itsParams, SIZEOF(ControlTemplate));
- END;
-
- {$IFC qDebug} { Any good reason besides TControl??? }
- {$Push} {$H-}
- WITH fSize DO
- IF (h > kMaxCoord) | (v > kMaxCoord) THEN
- ProgramBreak(ConcatNumber('The size in pixels of a TControl cannot exceed ', kMaxCoord));
- {$Pop}
- {$ENDC}
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAWriteRes}
-
- PROCEDURE TControl.WRes(theResource: ViewRsrcHndl;
- VAR itsParams: Ptr); OVERRIDE;
-
- VAR
- theSize: INTEGER;
- theFont: Str255;
- cnPtr: ControlTemplatePtr;
-
- BEGIN
- INHERITED WRes(theResource, itsParams);
-
- WITH fTextStyle DO
- BEGIN
- theSize := tsSize;
- {$Push} {$H-}
- GetPortFontInfo(tsFont, theFont, theSize);
- {$Pop}
- END;
-
- cnPtr := ControlTemplatePtr(ExpandPtrWStr(theResource, itsParams, SIZEOF(ControlTemplate),
- LENGTH(theFont)));
-
- WITH cnPtr^ DO
- BEGIN
- itsAdornment := fAdornment;
- itsPenSize := fPenSize;
- isSizable := fSizeable;
- isDimmed := fDimmed;
- isHilited := fHilite;
- canDismiss := fDismissesDialog;
- itsInset := fInset;
- WITH fTextStyle DO
- BEGIN
- itsTextFace := tsFace;
- itsTextSize := theSize;
- itsTextColor := tsColor;
- END;
- { itsFontName := theFont; }
- CopyStr255(theFont, PRStr(itsFontName));
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAWriteRes}
-
- PROCEDURE TControl.WriteRes(theResource: ViewRsrcHndl;
- VAR itsParams: Ptr); OVERRIDE;
-
- BEGIN
- gWResSignature := 'cntl'; gWResType := 'TControl';
- WRes(theResource, itsParams);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE TControl.ComputeSize(VAR newSize: VPoint); OVERRIDE;
-
- VAR
- deltaSz: Point;
-
- BEGIN
- INHERITED ComputeSize(newSize);
- IF NOT fSizeable THEN
- BEGIN { …we need to adjust the bot/right offset }
- WITH deltaSz DO
- BEGIN
- h := newSize.h - fSize.h; { Controls cannot be bigger than QD space. }
- v := newSize.v - fSize.v;
- END;
-
- IF Longint(deltaSz) <> 0 THEN { If view is going to change size, then… }
- {$Push} {$H-}
- AddPt(deltaSz, fInset.botRight); { …doesn't change control's actual size }
- {$Pop}
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- FUNCTION TControl.ContainsMouse(theMouse: VPoint): BOOLEAN; OVERRIDE;
-
- VAR
- aRect: Rect;
-
- BEGIN
- ControlArea(aRect);
- ContainsMouse := PtInRect(VPtToPt(theMouse), aRect);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE TControl.ControlArea(VAR theArea: Rect);
-
- BEGIN
- {$Push} {$H-}
- WITH fInset, fSize DO
- SetRect(theArea, left, top, h - right, v - bottom);
- {$Pop}
- IF adnShadow IN fAdornment THEN
- SubPt(fPenSize, theArea.botRight);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE TControl.Dim;
-
- VAR
- area: Rect;
-
- BEGIN
- {$IFC qDebug}
- AssumeFocused;
- {$ENDC}
-
- ControlArea(area);
- PenPat(gray);
- PenMode(patBic);
- PaintRect(area);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TControl.DimState(state, redraw: BOOLEAN);
-
- BEGIN
- IF state <> fDimmed THEN
- BEGIN
- fDimmed := state;
- IF redraw THEN
- DrawContents; { Draw change immediately }
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MASelCommand}
-
- FUNCTION TControl.DoMouseCommand(VAR theMouse: Point;
- VAR info: EventInfo;
- VAR hysteresis: Point): TCommand; OVERRIDE;
-
- VAR
- aControlTracker: TControlTracker;
-
- BEGIN
- NEW(aControlTracker);
- FailNIL(aControlTracker);
- aControlTracker.IControlTracker(SELF);
- DoMouseCommand := aControlTracker;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE TControl.Draw(area: Rect); OVERRIDE;
-
- VAR
- qdExtent: Rect;
-
- BEGIN
- IF fAdornment <> [] THEN
- BEGIN
- GetQDExtent(qdExtent);
- Adorn(qdExtent, fPenSize, fAdornment);
- END;
- IF fDimmed THEN
- Dim;
- IF fHilite THEN
- Hilite;
-
- INHERITED Draw(area);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S DlgRes}
-
- PROCEDURE TControl.Flash;
-
- VAR
- dontCare: Longint;
-
- BEGIN
- HiliteState(TRUE, kRedraw);
- Delay(8, dontCare);
- HiliteState(FALSE, kRedraw);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- FUNCTION TControl.Focus: BOOLEAN; OVERRIDE;
-
- VAR
- aTextStyle: TextStyle;
-
- BEGIN
- IF INHERITED Focus THEN
- BEGIN
- aTextStyle := fTextStyle;
- SetPortTextStyle(aTextStyle);
- PenNormal;
- Focus := TRUE;
- END
- ELSE
- Focus := FALSE;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE TControl.Hilite;
-
- VAR
- aRect: Rect;
-
- BEGIN
- {$IFC qDebug}
- AssumeFocused;
- {$ENDC}
-
- ControlArea(aRect);
- InvertRect(aRect);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TControl.HiliteState(state, redraw: BOOLEAN);
-
- BEGIN
- IF state <> fHilite THEN
- BEGIN
- fHilite := state;
- IF redraw & Focus & IsVisible THEN
- Hilite;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TControl.Inset(dh, dv: INTEGER;
- redraw: BOOLEAN);
-
- BEGIN
- IF fSizeable THEN
- BEGIN
- {$Push} {$H-}
- OffsetRect(fInset, dh, dv);
- WITH fSize DO
- Resize(h, v, redraw);
- {$Pop}
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TControl.InstallColor(theColor: RGBColor;
- redraw: BOOLEAN);
-
- BEGIN
- fTextStyle.tsColor := theColor;
- IF redraw THEN
- DrawContents;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TControl.InstallTextStyle(theTextStyle: TextStyle;
- redraw: BOOLEAN);
-
- BEGIN
- fTextStyle := theTextStyle;
- IF redraw THEN
- DrawContents;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- FUNCTION TControl.isDimmed: BOOLEAN;
-
- BEGIN
- isDimmed := fDimmed;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TControl.Resize(width, height: VCoordinate;
- invalidate: BOOLEAN); OVERRIDE;
-
- BEGIN
- { If we need to invalidate, then invalidate the whole view rather than
- the difference between the old and new size. }
- INHERITED Resize(width, height, invalidate);
- IF invalidate THEN
- ForceRedraw;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TControl.SetInset(newInset: Rect;
- redraw: BOOLEAN);
-
- BEGIN
- IF fSizeable THEN
- BEGIN
- fInset := newInset;
- WITH fSize DO
- {$Push} {$H-}
- Resize(h, v, redraw);
- {$Pop}
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MASelCommand}
-
- PROCEDURE TControl.TrackFeedback(anchorPoint, nextPoint: VPoint; turnItOn, mouseDidMove: BOOLEAN);
-
- BEGIN
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MASelCommand}
-
- PROCEDURE TControl.TrackMouse(aTrackPhase: TrackPhase;
- VAR anchorPoint, previousPoint, nextPoint: VPoint;
- mouseDidMove: BOOLEAN);
-
- BEGIN
- CASE aTrackPhase OF
- trackPress:
- HiliteState(TRUE, kRedraw);
- trackMove:
- HiliteState(ContainsMouse(nextPoint), kRedraw);
- trackRelease:
- BEGIN
- IF fHilite THEN
- HiliteState(FALSE, kRedraw);
- IF ContainsMouse(nextPoint) THEN
- DoChoice(SELF, fDefChoice);
- END;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- FUNCTION TControl.Validate: Longint;
-
- BEGIN
- Validate := noErr;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAFields}
-
- PROCEDURE TControl.Fields(PROCEDURE DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TControl', NIL, bClass);
- DoToField('fDefChoice', @fDefChoice, bInteger);
- DoToField('fHilite', @fHilite, bBoolean);
- DoToField('fDimmed', @fDimmed, bBoolean);
- DoToField('fSizeable', @fSizeable, bBoolean);
- DoToField('fDismissesDialog', @fDismissesDialog, bBoolean);
- DoToField('fAdornment', @fAdornment, bCntlAdornment);
- DoToField('fPenSize', @fPenSize, bPoint);
- DoToField('fInset', @fInset, bRect);
- {$Push} {$H-}
- TextStyleFields('fTextStyle', fTextStyle, DoToField);
- {$Pop}
- INHERITED Fields(DoToField);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAOpen}
-
- PROCEDURE TCtlMgr.ICtlMgr(itsSuperView: TView;
- itsLocation, itsSize: VPoint;
- itsHSizeDet, itsVSizeDet: SizeDeterminer;
- itsTitle: Str255;
- itsVal, itsMin, itsMax: Longint;
- itsProcID: INTEGER);
-
- VAR
- itsBounds: Rect;
-
- BEGIN
- fCMgrControl := NIL;
-
- { These MUST be initialized because SetLongValues tests each new value against }
- { the old value before doing anything. If the fLongMax value should happen to }
- { have a (bogus - uninitialized) value that matches itsMax, fBitsToShift won't }
- { be initialized and the control manager control will behave erratically. }
- fBitsToShift := 0;
- fLongVal := 0;
- fLongMin := 0;
- fLongMax := 0;
-
- IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
- WITH fSize DO
- {$Push} {$H-}
- SetRect(itsBounds, 0, 0, h, v);
- {$Pop}
- CreateCMgrControl(itsBounds, itsTitle, itsVal, itsMin, itsMax, itsProcID);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAOpen}
-
- PROCEDURE TCtlMgr.IRes(itsDocument: TDocument;
- itsSuperView: TView;
- VAR itsParams: Ptr);
-
- BEGIN
- fCMgrControl := NIL;
-
- { These MUST be initialized because SetLongValues tests each new value against }
- { the old value before doing anything. If the fLongMax value should happen to }
- { have a (bogus - uninitialized) value that matches itsMax, fBitsToShift won't }
- { be initialized and the control manager control will behave erratically. }
- fBitsToShift := 0;
- fLongVal := 0;
- fLongMin := 0;
- fLongMax := 0;
-
- INHERITED IRes(itsDocument, itsSuperView, itsParams);
- {The subclass must create the Control Manager control}
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAWriteRes}
-
- PROCEDURE TCtlMgr.WriteRes(theResource: ViewRsrcHndl;
- VAR itsParams: Ptr); OVERRIDE;
-
- BEGIN
- { We don't write TCtlMgrs… }
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAClose}
-
- PROCEDURE TCtlMgr.Free; OVERRIDE;
-
- BEGIN
- IF fCMgrControl <> NIL THEN
- BEGIN
- SetCMgrVisibility(FALSE); { This insures that HideControl, which will
- }
- { be called by SizeControl, doesn't do }
- { anything. HideControl seems to have some }
- { problems with large (~> 14000x14000) }
- SizeControl(fCMgrControl, 0, 0); { Prevent CMgr from erasing the control! }
- DisposeControl(fCMgrControl);
- fCMgrControl := NIL; { So BeInPort and others will be happy! }
- END;
- INHERITED Free;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TCtlMgr.BeInPort(itsPort: GrafPtr); OVERRIDE;
-
- BEGIN
- IF fCMgrControl <> NIL THEN
- WITH fCMgrControl^^ DO
- IF itsPort = NIL THEN
- BEGIN
- SetCMgrVisibility(FALSE);
- contrlOwner := WindowPtr(gWorkPort);
- END
- ELSE
- BEGIN
- SetCMgrVisibility(TRUE);
- contrlOwner := WindowPtr(itsPort);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAOpen}
-
- PROCEDURE TCtlMgr.CreateCMgrControl(itsBounds: Rect;
- itsTitle: Str255;
- itsVal, itsMin, itsMax: Longint;
- itsProcID: INTEGER);
-
- VAR
- itsPort: GrafPtr;
- aCMgrControl: ControlHandle;
- fi: FailInfo;
-
- PROCEDURE HandleFailure(error: OSErr;
- message: Longint);
-
- BEGIN
- Free;
- END;
-
- BEGIN
- itsPort := GetGrafPort;
- IF itsPort = NIL THEN
- itsPort := gWorkPort;
- CatchFailures(fi, HandleFailure);
- aCMgrControl := NewControl(itsPort, itsBounds, itsTitle, FALSE, 0, 0, 0,
- BOR(itsProcID, useWFont), Longint(SELF));
- FailNIL(aCMgrControl);
- Success(fi);
- { Keep control off Window's control list b/c the Window Mgr adds the regions of controls in
- the control list to the update region (see NOTE under DrawControls in Inside Mac volume I)
- generating an update event. }
- WITH WindowPeek(itsPort)^ DO
- controlList := controlList^^.nextControl;
-
- IF fDimmed THEN
- aCMgrControl^^.contrlHilite := 255;
- fCMgrControl := aCMgrControl;
-
- SetLongValues(itsVal, itsMin, itsMax, kDontRedraw); { Remember, the control was created
- with zeros, fix it up. }
-
- SetCMgrVisibility(itsPort <> gWorkPort);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TCtlMgr.DimState(state, redraw: BOOLEAN); OVERRIDE;
-
- PROCEDURE SetHilite;
-
- BEGIN
- HiliteControl(fCMgrControl, ORD(state) * 255);
- fDimmed := state;
- END;
-
- BEGIN
- IF fDimmed <> state THEN
- WhileFocused(SetHilite, redraw);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MASelCommand}
-
- FUNCTION TCtlMgr.DoMouseCommand(VAR theMouse: Point;
- VAR info: EventInfo;
- VAR hysteresis: Point): TCommand; OVERRIDE;
-
- BEGIN
- IF TestControl(fCMgrControl, theMouse) <> 0 THEN
- IF TrackControl(fCMgrControl, theMouse, NIL) <> 0 THEN
- DoChoice(SELF, fDefChoice);
- DoMouseCommand := NIL;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE TCtlMgr.Draw(area: Rect); OVERRIDE;
-
- VAR
- savedOwner: WindowPtr;
- qdExtent: Rect;
-
- BEGIN
- IF IsCMgrVisible THEN
- BEGIN { Set the port in case we're printing }
- {$IFC qDebug}
- AssumeFocused;
- {$ENDC}
-
- WITH fCMgrControl^^ DO
- BEGIN
- savedOwner := contrlOwner;
- contrlOwner := WindowPtr(thePort);
- END;
-
- PenNormal; {NECESSARY?}
-
- IF qNeedsROM128K | gConfiguration.hasROM128K THEN
- Draw1Control(fCMgrControl)
- ELSE
- BEGIN
- SetCMgrVisibility(FALSE); { Force ShowControl to redraw }
- ShowControl(fCMgrControl);
- END;
-
- fCMgrControl^^.contrlOwner := savedOwner;
- END;
-
-
- {!!! Not in 2.0
- because we found we needed a IsDrawnDimmed and a IsDrawnHilited and it's too late to add them.
- If you change the drawing behaviour of some ancestor you must duplicate that behaviour here
- if you want it reflected in TCtlMgr and subclasses. Will be fixed in next release. Sorry.
- INHERITED Draw(area);
- }
-
- IF fAdornment <> [] THEN
- BEGIN
- GetQDExtent(qdExtent);
- Adorn(qdExtent, fPenSize, fAdornment);
- END;
-
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- FUNCTION TCtlMgr.IsCMgrVisible: BOOLEAN;
-
- BEGIN
- IsCMgrVisible := (fCMgrControl <> NIL) & (fCMgrControl^^.contrlVis = 255);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- FUNCTION TCtlMgr.GetMax: INTEGER;
-
- BEGIN
- GetMax := GetCtlMax(fCMgrControl)
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- FUNCTION TCtlMgr.GetMin: INTEGER;
-
- BEGIN
- GetMin := GetCtlMin(fCMgrControl)
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE TCtlMgr.GetText(VAR theText: Str255);
-
- BEGIN
- { theText := fCMgrControl^^.contrlTitle; }
- CopyStr255(fCMgrControl^^.contrlTitle, @theText);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- FUNCTION TCtlMgr.GetVal: INTEGER;
-
- BEGIN
- GetVal := GetCtlValue(fCMgrControl)
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TCtlMgr.HiliteState(state, redraw: BOOLEAN); OVERRIDE;
-
- PROCEDURE SetHilite;
-
- BEGIN
- HiliteControl(fCMgrControl, ORD(state) * 10);
- END;
-
- BEGIN
- IF fHilite <> state THEN
- WhileFocused(SetHilite, redraw);
- fHilite := state;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TCtlMgr.Resize(width, height: VCoordinate;
- invalidate: BOOLEAN); OVERRIDE;
-
- PROCEDURE ResizeCMgrControl;
-
- VAR
- aRect: Rect;
-
- BEGIN
- WITH fInset DO
- {$Push} {$H-}
- SetRect(aRect, left, top, width - right, height - bottom);
- {$Pop}
- WITH aRect DO
- BEGIN
- MoveControl(fCMgrControl, left, top);
- SizeControl(fCMgrControl, ABS(right - left), ABS(bottom - top));
- END;
- END;
-
- BEGIN
- IF fSizeable & (fCMgrControl <> NIL) THEN
- WhileFocused(ResizeCMgrControl, kDontRedraw);
- INHERITED Resize(width, height, invalidate);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE TCtlMgr.SetCMgrVisibility(beVisible: BOOLEAN);
-
- BEGIN
- IF fCMgrControl <> NIL THEN
- IF beVisible THEN
- fCMgrControl^^.contrlVis := 255
- ELSE
- fCMgrControl^^.contrlVis := 0;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE TCtlMgr.SetMax(itsMax: INTEGER;
- redraw: BOOLEAN);
-
- PROCEDURE DoSetMax;
-
- BEGIN
- SetCtlMax(fCMgrControl, itsMax);
- END;
-
- BEGIN
- WhileFocused(DoSetMax, redraw);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE TCtlMgr.SetMin(itsMin: INTEGER;
- redraw: BOOLEAN);
-
- PROCEDURE DoSetMin;
-
- BEGIN
- SetCtlMin(fCMgrControl, itsMin);
- END;
-
- BEGIN
- WhileFocused(DoSetMin, redraw);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TCtlMgr.SetText(itsText: Str255;
- redraw: BOOLEAN);
-
- VAR
- currentText: Str255;
-
- PROCEDURE DoSetText;
-
- BEGIN
- GetCTitle(fCMgrControl, currentText);
- IF currentText <> itsText THEN
- SetCTitle(fCMgrControl, itsText);
- END;
-
- BEGIN
- WhileFocused(DoSetText, redraw);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE TCtlMgr.SetVal(newVal: INTEGER;
- redraw: BOOLEAN);
-
- PROCEDURE DoSetVal;
-
- BEGIN
- SetCtlValue(fCMgrControl, newVal);
- END;
-
- BEGIN
- IF GetCtlValue(fCMgrControl) <> newVal THEN
- WhileFocused(DoSetVal, redraw);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE TCtlMgr.SetValues(itsVal, itsMin, itsMax: INTEGER;
- redraw: BOOLEAN);
-
- PROCEDURE DoSetValues;
-
- BEGIN
- SetCtlMin(fCMgrControl, itsMin);
- SetCtlMax(fCMgrControl, itsMax);
- SetCtlValue(fCMgrControl, itsVal);
- END;
-
- BEGIN
- WhileFocused(DoSetValues, redraw);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE TCtlMgr.WhileFocused(PROCEDURE DoToControl;
- redraw: BOOLEAN);
-
- VAR
- savedFocusedView: TView;
- wasVisible: BOOLEAN;
-
- BEGIN
- IF fCMgrControl <> NIL THEN
- BEGIN
- IF redraw & Focus THEN
- DoToControl
- ELSE
- BEGIN
- wasVisible := IsCMgrVisible;
- SetCMgrVisibility(FALSE);
- DoToControl;
- IF wasVisible & (NOT IsCMgrVisible) { If DoToControl didn't set it }
- THEN
- SetCMgrVisibility(wasVisible); { …restore visibility }
- END;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- FUNCTION TCtlMgr.GetLongMax: VCoordinate;
-
- BEGIN
- GetLongMax := fLongMax;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- FUNCTION TCtlMgr.GetLongMin: VCoordinate;
-
- BEGIN
- GetLongMin := fLongMin;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- FUNCTION TCtlMgr.GetLongVal: VCoordinate;
-
- BEGIN
- GetLongVal := fLongVal;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE TCtlMgr.SetLongMax(itsMax: VCoordinate;
- redraw: BOOLEAN);
-
- BEGIN
- IF itsMax <> fLongMax THEN
- BEGIN
- fLongMax := itsMax;
- fBitsToShift := 0;
- WHILE itsMax > MAXINT DO
- BEGIN
- itsMax := BSR(itsMax, 1);
- fBitsToShift := fBitsToShift + 1;
- END;
- SetMax(itsMax, redraw);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE TCtlMgr.SetLongMin(itsMin: VCoordinate;
- redraw: BOOLEAN);
-
- BEGIN
- IF itsMin <> fLongMin THEN
- BEGIN
- fLongMin := itsMin;
- SetMin(BSR(itsMin, fBitsToShift), redraw);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE TCtlMgr.SetLongVal(itsVal: VCoordinate;
- redraw: BOOLEAN);
-
- BEGIN
- itsVal := Max(fLongMin, Min(itsVal, fLongMax));
- IF itsVal <> fLongVal THEN
- BEGIN
- fLongVal := itsVal;
- SetVal(BSR(itsVal, fBitsToShift), redraw);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE TCtlMgr.SetLongValues(itsVal, itsMin, itsMax: VCoordinate;
- redraw: BOOLEAN);
-
- BEGIN
- SetLongMax(itsMax, redraw); { Must be first to get fBitsToShift setup }
- SetLongMin(itsMin, redraw);
- SetLongVal(itsVal, redraw);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAFields}
-
- PROCEDURE TCtlMgr.Fields(PROCEDURE DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TCtlMgr', NIL, bClass);
- DoToField('fCMgrControl', @fCMgrControl, bControlHandle);
- DoToField('fBitsToShift', @fBitsToShift, bInteger);
- DoToField('fLongVal', @fLongVal, bLongInt);
- DoToField('fLongMin', @fLongMin, bLongInt);
- DoToField('fLongMax', @fLongMax, bLongInt);
- INHERITED Fields(DoToField);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAOpen}
-
- PROCEDURE TScrollBar.IScrollBar(itsSuperView: TView;
- itsLocation, itsSize: VPoint;
- itsHSizeDet, itsVSizeDet: SizeDeterminer;
- itsDirection: VHSelect;
- itsVal, itsMin, itsMax: Longint);
-
- BEGIN
- ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, '', itsVal, itsMin,
- itsMax, scrollBarProc);
- fDirection := itsDirection;
-
- IF itsDirection = h THEN
- fDefChoice := mHScrollBarHit
- ELSE
- fDefChoice := mVScrollBarHit;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAOpen}
-
- PROCEDURE TScrollBar.IRes(itsDocument: TDocument;
- itsSuperView: TView;
- VAR itsParams: Ptr); OVERRIDE;
-
- VAR
- area: Rect;
-
- BEGIN
- INHERITED IRes(itsDocument, itsSuperView, itsParams);
-
- ControlArea(area);
- WITH ScrollBarTemplatePtr(itsParams)^ DO
- CreateCMgrControl(area, '', value, minimum, maximum, scrollBarProc);
-
- WITH area DO
- IF (bottom - top) >= (right - left) THEN
- BEGIN
- fDirection := v;
- fDefChoice := mVScrollBarHit;
- END
- ELSE
- BEGIN
- fDirection := h;
- fDefChoice := mHScrollBarHit;
- END;
-
- OffsetPtr(itsParams, SIZEOF(ScrollBarTemplate));
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAWriteRes}
-
- PROCEDURE TScrollBar.WRes(theResource: ViewRsrcHndl;
- VAR itsParams: Ptr); OVERRIDE;
-
- VAR
- sbPtr: ScrollBarTemplatePtr;
-
- BEGIN
- INHERITED WRes(theResource, itsParams);
-
- sbPtr := ScrollBarTemplatePtr(ExpandPtr(theResource, itsParams, SIZEOF(ScrollBarTemplate)));
-
- WITH sbPtr^ DO
- BEGIN
- value := fLongVal;
- minimum := fLongMin;
- maximum := fLongMax;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAWriteRes}
-
- PROCEDURE TScrollBar.WriteRes(theResource: ViewRsrcHndl;
- VAR itsParams: Ptr); OVERRIDE;
-
- BEGIN
- gWResSignature := 'sbar'; gWResType := 'TScrollBar';
- WRes(theResource, itsParams);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE TScrollBar.ActionProc(partCode: INTEGER);
-
- VAR
- backwards: BOOLEAN;
-
- BEGIN
- IF partCode <> 0 THEN
- BEGIN
- backwards := (partCode = inUpButton) | (partCode = inPageUp);
-
- IF (backwards & (fLongVal > fLongMin)) | ((NOT backwards) & (fLongVal < fLongMax)) THEN
- TrackScrollBar(partCode);
-
- Update; { Make sure that we're in synch before returning ??? How can this be controlable?}
- IF Focus THEN; { make sure i am looking at myself… e.e. cummings }
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAScroll}
-
- PROCEDURE TScrollBar.DeltaValue(delta: VCoordinate);
-
- BEGIN
- IF delta <> 0 THEN
- BEGIN
- {Ensure that delta does not cause an overflow (or underflow)}
- IF delta > 0 THEN
- delta := Min(delta, fLongMax - fLongVal)
- ELSE
- delta := Max(delta, fLongMin - fLongVal);
-
- SetLongVal(fLongVal + delta, TRUE);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAScroll}
-
- FUNCTION TScrollBar.DoMouseCommand(VAR theMouse: Point;
- VAR info: EventInfo;
- VAR hysteresis: Point): TCommand; OVERRIDE;
-
- VAR
- partCode: INTEGER;
- oldLongValue: VCoordinate;
- newLongValue: VCoordinate;
-
- BEGIN
- {$IFC qDebug}
- AssumeFocused;
- {$ENDC}
-
- oldLongValue := fLongVal;
-
- CASE TestControl(fCMgrControl, theMouse) OF
- inUpButton, inDownButton, inPageUp, inPageDown:
- BEGIN
- partCode := TrackControl(fCMgrControl, theMouse, @ActionProcForTScrollBar);
-
- { This method MUST inform its superview of the change!
- Thanks to GLB! }
- IF fLongVal <> oldLongValue THEN
- DoChoice(SELF, fDefChoice);
- END;
- inThumb:
- IF TrackControl(fCMgrControl, theMouse, NIL) = inThumb THEN
- BEGIN
- {If thumb is dragged to bottom of scroll bar then ensure that
- the new long value is set to the maximum long value.
-
- We get killed by side effects if we don't use a temporary variable here.
- This doesn't show up in the TSScrollBar class because this code is
- overridden, but it will show up in derived classes that depend on this
- code }
- IF GetVal = GetMax THEN
- newLongValue := fLongMax
- ELSE
- BEGIN
- newLongValue := BSL(Longint(GetVal), fBitsToShift);
- END;
-
- SetLongVal(newLongValue, kRedraw);
-
- { This method MUST inform its superview of the change! }
- IF fLongVal <> oldLongValue THEN
- DoChoice(SELF, fDefChoice);
- END;
- END;
- DoMouseCommand := NIL;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE TScrollBar.TrackScrollBar(partCode: INTEGER);
-
- BEGIN
- IF (partCode = inPageUp) | (partCode = inUpButton) THEN
- DeltaValue( - 1)
- ELSE
- DeltaValue(1);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAFields}
-
- PROCEDURE TScrollBar.Fields(PROCEDURE DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TScrollBar', NIL, bClass);
- DoToField('fDirection', @fDirection, bVHSelect);
- INHERITED Fields(DoToField);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAOpen}
-
- PROCEDURE TSScrollBar.ISScrollBar(itsSuperView: TView;
- itsLocation, itsSize: VPoint;
- itsHSizeDet, itsVSizeDet: SizeDeterminer;
- itsDirection: VHSelect;
- itsMax: Longint;
- itsScroller: TScroller);
-
- VAR
- itsWindow: TWindow;
- fi: FailInfo;
-
- PROCEDURE HandleFailure(error: OSErr;
- message: Longint);
-
- BEGIN
- Free;
- END;
-
- BEGIN
- fScrollers := NIL;
- IScrollBar(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsDirection, 0, 0,
- itsMax);
- itsWindow := GetWindow;
- SetCMgrVisibility((itsWindow <> NIL) & itsWindow.fIsActive);
-
- CatchFailures(fi, HandleFailure);
- fScrollers := NewList;
- {$IFC qDebug}
- fScrollers.SetEltType('TScroller');
- {$ENDC}
- AttachScroller(itsScroller);
- Success(fi);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAOpen}
-
- PROCEDURE TSScrollBar.IRes(itsDocument: TDocument;
- itsSuperView: TView;
- VAR itsParams: Ptr); OVERRIDE;
-
- VAR
- itsWindow: TWindow;
- fi: FailInfo;
-
- PROCEDURE HandleFailure(error: OSErr;
- message: Longint);
-
- BEGIN
- Free;
- END;
-
- BEGIN
- INHERITED IRes(itsDocument, itsSuperView, itsParams);
- itsWindow := GetWindow;
- SetCMgrVisibility((itsWindow <> NIL) & itsWindow.fIsActive);
-
- CatchFailures(fi, HandleFailure);
- fScrollers := NewList;
- {$IFC qDebug}
- fScrollers.SetEltType('TScroller');
- {$ENDC}
- Success(fi);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAWriteRes}
-
- PROCEDURE TSScrollBar.WriteRes(theResource: ViewRsrcHndl;
- VAR itsParams: Ptr); OVERRIDE;
-
- BEGIN
- { We never want to write TSScrollbars. TScroller will create its own }
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAClose}
-
- PROCEDURE TSScrollBar.Free; OVERRIDE;
-
- PROCEDURE DetachFromScroller(theScroller: TScroller);
-
- BEGIN
- IF theScroller.fScrollBars[fDirection] = SELF THEN
- theScroller.HaveScrollBar(NIL, fDirection);
- END;
-
- BEGIN
- IF fScrollers <> NIL THEN
- fScrollers.Each(DetachFromScroller);
- FreeIfObject(fScrollers);
- fScrollers := NIL;
-
- INHERITED Free;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAActivate}
-
- PROCEDURE TSScrollBar.Activate(entering: BOOLEAN); OVERRIDE;
-
- PROCEDURE SetScrollBar;
-
- VAR
- itsRect: Rect;
-
- BEGIN
- itsRect := fCMgrControl^^.contrlRect;
- IF entering THEN
- ShowControl(fCMgrControl)
- ELSE
- BEGIN
- HideControl(fCMgrControl);
- { Thanks Larry 11/2/89 }
- IF IsFocused THEN
- Draw(itsRect); { Get the frame drawn. }
- END;
- IF IsFocused THEN
- ValidRect(itsRect); { Because Control Manager invalidates it. }
- END;
-
- BEGIN
- WhileFocused(SetScrollBar, Focus);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAOpen}
-
- PROCEDURE TSScrollBar.AttachScroller(itsScroller: TScroller);
-
- BEGIN
- IF itsScroller <> NIL THEN
- BEGIN
- fScrollers.Insert(itsScroller);
- itsScroller.HaveScrollBar(SELF, fDirection);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TSScrollBar.BeInPort(itsPort: GrafPtr); OVERRIDE;
-
- VAR
- itsWindow: TWindow;
-
- BEGIN
- INHERITED BeInPort(itsPort);
- itsWindow := GetWindow;
- SetCMgrVisibility((itsWindow <> NIL) & itsWindow.fIsActive);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAScroll}
-
- FUNCTION TSScrollBar.DoMouseCommand(VAR theMouse: Point;
- VAR info: EventInfo;
- VAR hysteresis: Point): TCommand; OVERRIDE;
-
- VAR
- partCode: INTEGER;
- sBarDelta: Longint;
-
- PROCEDURE ScrollToThumb(theView: TScroller);
-
- BEGIN
- sBarDelta := sBarDelta + theView.ScrollRelative(fDirection, fLongVal);
- END;
-
- BEGIN
- {$IFC qDebug}
- AssumeFocused;
- {$ENDC}
-
- GetFocus(gSaveFocusRec);
- IF TestControl(fCMgrControl, theMouse) = inThumb THEN
- BEGIN
- IF TrackControl(fCMgrControl, theMouse, NIL) = inThumb THEN
- BEGIN
- sBarDelta := 0;
- {If thumb is dragged to bottom of scroll bar then ensure that
- the new long value is set to the maximum long value.}
- IF GetVal = GetMax THEN
- fLongVal := fLongMax
- ELSE
- fLongVal := BSL(GetVal, fBitsToShift);
- fScrollers.Each(ScrollToThumb);
- SetFocus(gSaveFocusRec);
- IF sBarDelta <> 0 THEN
- SetLongVal(fLongVal + sBarDelta, kRedraw);
- END;
- DoMouseCommand := NIL;
- END
- ELSE
- DoMouseCommand := INHERITED DoMouseCommand(theMouse, info, hysteresis);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAControlRes}
-
- PROCEDURE TSScrollBar.Draw(area: Rect); OVERRIDE;
-
- VAR
- itsRect: Rect;
-
- BEGIN
- {$IFC qDebug}
- AssumeFocused;
- {$ENDC}
-
- IF NOT IsCMgrVisible THEN
- BEGIN
- PenNormal;
- itsRect := fCMgrControl^^.contrlRect;
- FrameRect(itsRect);
- END;
-
- INHERITED Draw(area);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAScroll}
-
- PROCEDURE TSScrollBar.TrackScrollBar(partCode: INTEGER);
-
- VAR
- sBarDelta: Longint;
-
- PROCEDURE ScrollView(theScroller: TScroller);
-
- BEGIN
- sBarDelta := sBarDelta + theScroller.ScrollStep(fDirection, partCode);
- END;
-
- BEGIN
- sBarDelta := 0;
- fScrollers.Each(ScrollView);
- SetFocus(gSaveFocusRec); { gSaveFocusRec was set by DoMouseCommand }
- DeltaValue(sBarDelta);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAFields}
-
- PROCEDURE TSScrollBar.Fields(PROCEDURE DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TSScrollBar', NIL, bClass);
- DoToField('fScrollers', @fScrollers, bObject);
- INHERITED Fields(DoToField);
- END;
-